import type {
  User,
  CodeType,
  UserInfo,
  PatientList,
  Patient,
} from "@/types/user";
import { request } from "@/utils/request";

/**
 * 通过密码登录
 * @param mobile string
 * @param password string
 * @returns Promise
 */
export const loginByPassword = (mobile: string, password: string) => {
  return request<User>("/login/password", "POST", { mobile, password });
};

/**
 * 发送验证码
 * @param mobile string
 * @param type CodeType
 * @returns Promise
 */
export const sendMobileCode = (mobile: string, type: CodeType) => {
  return request("/code", "GET", { mobile, type });
};

/**
 * 通过验证码登录
 * @param mobile string
 * @param code string
 * @returns Promise
 */
export const loginByCode = (mobile: string, code: string) => {
  return request<User>("/login", "POST", { mobile, code });
};

/**
 * 获取个人信息
 * @returns Promise
 */
export const getUserInfo = () => {
  return request<UserInfo>("/patient/myUser");
};

/**
 * 患者信息列表
 * @returns Promise
 */
export const getPatientList = () => {
  return request<PatientList>("/patient/myList");
};

/**
 * 添加患者信息
 * @param patient Patient
 * @returns Promise
 */
export const addPatient = (patient: Patient) => {
  return request("/patient/add", "POST", patient);
};

/**
 * 编辑患者信息
 * @param patient Patient
 * @returns Promise
 */
export const editPatient = (patient: Patient) => {
  return request("/patient/update", "PUT", patient);
};

/**
 * 删除患者信息
 * @param id string
 * @returns Promise
 */
export const delPatient = (id: string) => {
  return request(`/patient/del/${id}`, "DELETE");
};
